﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wiwi.Models;
using Wiwi.ViewModels;
using System.Web.Security;
namespace Wiwi.Controllers
{
    public class DealingController : Controller
    {
        //
        // GET: /Dealing/

        public ActionResult Index()
        {
            ProfileView pv = new ProfileView();
            //WiwiEntities1 db = new WiwiEntities1();
            //MembershipUser usr = Membership.GetUser();
            //Guid guSupp = new Guid(usr.ProviderUserKey.ToString());
            //A_vUserTable ut = db.A_vUserTable.SingleOrDefault(c => c.UserID == guSupp);
            //pv.Usr = ut;
            //var comms = (from cm in db.A_vWantCommunication where cm.UserID == guSupp orderby cm.CommDate descending select cm).ToList();
            //pv.comms = comms;
            //var pitches = (from pit in db.A_vPitchesSupplier where pit.SupplierID == guSupp orderby pit.WiwiDate descending select pit).ToList();
            //pv.VPitches = pitches;
            return View(pv);
        }
        [Authorize]
        public ActionResult PitchComm(string Wid,string clientID)
        {
            //MembershipUser usr = Membership.GetUser();
            //Guid gu = new Guid(Wid);
            //Guid guClient = new Guid(clientID);
            //Guid gusr = new Guid(usr.ProviderUserKey.ToString());
            //WiwiEntities1 db = new WiwiEntities1();
            WantCommunication wc = new WantCommunication();
            //A_vPitchesSupplier ws = db.A_vPitchesSupplier.SingleOrDefault(c => c.SupplierID == gusr && c.UserID == guClient && c.WantID == gu);
            //if (ws.IsSelected == true) wc.PicthApprove = 1;
            //A_vWant wnt = db.A_vWant.SingleOrDefault(c => c.WantID == gu && c.UserID == guClient);
            //wc.wnt = wnt;
            //wc.SupplierID = usr.ProviderUserKey.ToString();
            //var comms = (from cm in db.A_vWantCommunication where cm.WantID == gu && (cm.FrmUserID == gusr || cm.UserID == gusr) orderby cm.CommDate descending select cm).ToList();
            //wc.comms = comms;
            return View(wc);
        }
        [HttpPost]
        [Authorize]
        public ActionResult PitchComm(WantCommunication wc)
        {
            //MembershipUser usr = Membership.GetUser();
            //Guid gu = new Guid(wc.wnt.WantID.ToString());
            //Guid gusr = new Guid(usr.ProviderUserKey.ToString());
            //WiwiEntities1 db = new WiwiEntities1();
            //A_vWant wnt = db.A_vWant.SingleOrDefault(c => c.WantID == wc.wnt.WantID && c.UserID == wc.wnt.UserID);
            //A_WantCommunication com = new A_WantCommunication();
            //com.Act_ID = CommonFunc.GetActivityByCode("PITREP", db);
            //com.CommDate = DateTime.Now;
            //com.Comments = wc.ReplyText;
            //com.FrmUserID = gusr;
            //com.WantID = wnt.WantID;
            //com.UserID = wnt.UserID;
            //db.AddToA_WantCommunication(com);
            //db.SaveChanges();
            return RedirectToAction("../Home/Profile/");
        }
    }
}
